
public class Test {
    public static void main(String[] args) {
        String str = " hello%$$%@#$%world 哈哈哈 " ;
        System.out.println(str.toUpperCase());
        System.out.println(str.toLowerCase());
    }
    public static void main16(String[] args) {
        String str = " hello world " ;
        System.out.println("["+str+"]");
        System.out.println("["+str.trim()+"]");
    }
    public static void main15(String[] args) {
        String str = "helloworld" ;
        System.out.println(str.substring(5));
        System.out.println(str.substring(0, 5));
    }
    public static void main14(String[] args) {

        String str = "hello world hello student" ;
        String[] result = str.split(" ",2) ;
        for(String s: result) {
            System.out.println(s);
        }

    }
    public static void main13(String[] args) {
        String str = "helloworld" ;
        System.out.println(str.replaceAll("l", "_"));
        System.out.println(str.replaceFirst("l", "_"));

    }
    public static void main12(String[] args) {
        String s = String.format("%d-%d-%d", 2022, 7,31);
        System.out.println(s);
    }

    public static void main11(String[] args) {
        String str = "hello";
// 字符串转数组
        char[] ch = str.toCharArray();
        for (int i = 0; i < ch.length; i++) {
            System.out.print(ch[i]);
        }
        System.out.println();
// 数组转字符串
        String s2 = new String(ch);
        System.out.println(s2);
    }
    public static void main10(String[] args) {
        String s1 = String.valueOf(1234);
        String s2 = String.valueOf(12.34);
        String s3 = String.valueOf(true);
    }
    public static void main9(String[] args) {
        String s1 = new String("hello");
        String s2 = new String("world");
        String s3 = s1;
        System.out.println(s1.length()); // 获取字符串长度---输出5
        System.out.println(s1.isEmpty()); // 如果字符串长度为0，返回true，否则返回false
    }
    public static void main8(String[] args) {
// 使用常量串构造
        String s1 = "hello bit";
        System.out.println(s1);
// 直接newString对象
        String s2 = new String("hello bit");
        System.out.println(s1);
// 使用字符数组进行构造
        char[] array = {'h','e','l','l','o','b','i','t'};
        String s3 = new String(array);
        System.out.println(s1);
    }


    public static void main7(String[] args) {
        char[] ch = new char[]{'a', 'b', 'c'};
        String s1 = new String(ch); // s1对象并不在常量池中
//s1.intern(); // s1.intern()；调用之后，会将s1对象的引用放入到常量池中
        String s2 = "abc"; // "abc" 在常量池中存在了，s2创建时直接用常量池中"abc"的引用
        System.out.println(s1 == s2);




    }
    // 输出false
// 将上述方法打开之后，就会输出true
    public static void main6(String[] args) {
        String  str1 = "hello";
        String  str2 = "hello";
        String  str3 = new String("hello");
    }


    public static void main5(String[] args) {
        //数字转成字符串
        String str = String.valueOf(123);
        System.out.println(str);

    }
    public static void main4(String[] args) {
        String  str1 = "hello";
        System.out.println(str1.indexOf('e'));
    }
    public static void main3(String[] args) {
        //忽略大小写进行比较
        String  str1 = "hello";
        String  str2 = "HELLO";
        //比较是否相同
        System.out.println(str1.equals(str2));
        System.out.println(str1.equalsIgnoreCase(str2));
        System.out.println("================");
        //比较大小
        System.out.println(str1.compareTo(str2));
        System.out.println(str1.compareToIgnoreCase(str2));
    }
    public static void main2(String[] args) {
        String  str1 = "hello";

        String str2 = new String("abc");

        System.out.println(str1.equals(str2));
        System.out.println(str1.compareTo(str2));
    }
    public static void main1(String[] args) {
        String  str1 = "hello";

        String str2 = new String("abc");

        char[] chars = {'a','b','c'};
        String str3 = new String(chars);
        System.out.println(str1.length());

    }
}
